<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:f="http://xmlns.jcp.org/jsf/core" 
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
	xmlns:cc="http://xmlns.jcp.org/jsf/composite">

	<cc:interface>
		<cc:attribute name="workitem"></cc:attribute>
		<cc:attribute name="styleClass"></cc:attribute>
		<cc:attribute name="showattachments" default="false" type="java.lang.Boolean"></cc:attribute>
		<cc:attribute name="labelButton" default="File Upload"></cc:attribute>
		<cc:attribute name="labelHelp" default="drop files here..."></cc:attribute>
		<cc:attribute name="workitem"></cc:attribute>
		<cc:attribute name="context_url"></cc:attribute>
	</cc:interface>

	<cc:implementation>
		<!-- #{fileUploadController.setWorkitem(cc.attrs.workitem)} -->
		<h:commandScript name="refreshFileUploadAjaxTable" render="#{uploadFileListComponent.clientId}"  />
		<div class="imixsfileupload #{cc.attrs.styleClass}">
			<input id="imixsfileInput" class="imixsfileuploadinput imixsfileuploadinputajax" type="file" name="files[]"
					data-url="#{request.contextPath}/fileupload/?cid=#{fileUploadController.getCID()}"
					multiple="multiple" />
			<label for="imixsfileInput">#{cc.attrs.labelButton}</label><span class="drop-area">#{cc.attrs.labelHelp}</span>
			<h:panelGroup layout="block" styleClass="imixsfileupload-table" id="uploadFileListID" binding="#{uploadFileListComponent}">
				<!-- show ajax uploads -->
				<h:dataTable value="#{fileUploadController.fileUploads}" var="fileData"
				    rendered="#{! empty fileUploadController.fileUploads}"
					styleClass="imixsFileUpload_uploadlist" >
						<h:column>
							<f:facet name="header">File Name</f:facet>

							


							<h:outputText escape="false" value="&lt;a class='imixsFileUpload_file' target='_blank' href='" />
							<h:outputText escape="false"
								value="#{cc.attrs.context_url}/fileupload/file/#{fileData.name}?cid=#{fileUploadController.getCID()}" />
							<h:outputText escape="false" value="'&gt;#{fileData.name}&lt;/a&gt;" />
						</h:column>
						<h:column>
							<f:facet name="header">Size</f:facet>
							#{fileUploadController.getFileSize(fileData.name)}
						</h:column>
						<h:column>
							<f:facet name="header">User Info</f:facet>
							#{fileUploadController.getUserInfo(fileData.name)}
						</h:column>
						<h:column><f:facet name="header">Type</f:facet>
							#{fileData.contentType}
						</h:column>
						<!--  delete stored file  -->
						<h:column>
							<h:commandLink value="🗙"
								styleClass="remove-link"
								actionListener="#{fileUploadController.removeFileUpload(fileData.name)}">
								<f:ajax
									render="#{uploadFileListComponent.clientId}"/>
								<f:param name="cid" value="#{fileUploadController.getCID()}" />
							</h:commandLink>
						</h:column>
				</h:dataTable>
			</h:panelGroup>
			<!-- show  attachments from workitem -->
			<ui:fragment rendered="#{cc.attrs.showattachments}">
				<h:panelGroup layout="block" styleClass="imixsfileupload-table" id="persistendFileListID">
					<!-- attached files -->
					<h:dataTable value="#{cc.attrs.workitem.fileData}" var="fileData"
						styleClass="imixsFileUpload_uploadlist" >
							<h:column>
								<f:facet name="header">File Name</f:facet>
								<h:outputText escape="false" value="&lt;a class='imixsFileUpload_file' target='_blank' href='" />
								<h:outputText escape="false"
									value="#{cc.attrs.context_url}/file/#{fileData.name}" />
								<h:outputText escape="false" value="'&gt;#{fileData.name}&lt;/a&gt;" />
							</h:column>
							<h:column>
								<f:facet name="header">Size</f:facet>
								#{fileUploadController.getFileSize(fileData.name)}
							</h:column>
							<h:column>
								<f:facet name="header">User Info</f:facet>
								#{fileUploadController.getUserInfo(fileData.name)}
							</h:column>
							<h:column><f:facet name="header">Type</f:facet>
								#{fileData.contentType}
							</h:column>
							<!--  delete stored file  -->
							<h:column>
								<h:commandLink value="🗙" styleClass="remove-link"
									actionListener="#{fileUploadController.removeAttachedFile(fileData.name)}">
									<f:ajax render=":#{component.parent.parent.parent.clientId}"/>
									<f:param name="cid" value="#{fileUploadController.getCID()}" />
								</h:commandLink>
							</h:column>
					</h:dataTable>
				</h:panelGroup>
			</ui:fragment>
		</div>
	</cc:implementation>
</ui:composition>